package com.jctrip.hotel.source.xxl.meituan.thread;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.service.meituan.MeituanTaskService;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: ch
 * @CreateTime: 2024/1/5 1:17 PM
 * @Description:
 */
@Slf4j
public class SyncHotelStaticInfoTaskThread implements Runnable {
    private final String accessKey;
    private final String secretKey;
    private final Integer partnerId;

    public SyncHotelStaticInfoTaskThread(String accessKey, String secretKey, Integer partnerId) {
        this.accessKey = accessKey;
        this.secretKey = secretKey;
        this.partnerId = partnerId;
    }

    @Override
    public void run() {
        try {
            RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);
            MeituanTaskService meituanTaskService = BeanContext.getApplicationContext().getBean(MeituanTaskService.class);

            while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_MEITUAN_HOTELId_LIST)>0){
                try{
                    String hotelId = redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_MEITUAN_HOTELId_LIST).toString();
                    if(null == hotelId){
                        continue;
                    }
                    meituanTaskService.syncHotelStaticInfo(partnerId, accessKey, secretKey, hotelId);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
